package com.wsq.demo01.mapper;

import com.wsq.demo01.pojo.StudentInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {

    /*重置数据表的两个方法:truncateTable()和addStudentInfo(StudentInfo studentInfo)*/
    /*truncate*/
    @Update("truncate table student_info")
    int truncateTable();

    /*add*/
    @Insert("insert into student_info values (#{id}, #{name}, #{Stu_id}, #{Depart}, #{grade}, #{sex})")
    void addStudentInfo(StudentInfo studentInfo);

    /*查询全部学生信息*/
    List<StudentInfo> queryStudentList();

    /*获取接口body参数中name属性，删除指定学生*/
    void deleteStudent(String name);

    /*获取接口body参数，新增学生信息*/
    void testAdd(Map<String, Object> map);

    /*获取接口body参数，修改学生信息*/
    void testUpdate(Map<String, Object> map);

    /*新增学生信息时，通过此方法判断id对应的学生信息不存在*/
    @Select("select * from student_info where id =#{id}")
    StudentInfo findUserById(Integer id);

    /*修改学生信息时，通过此方法判断name对应的学生信息存在*/
    @Select("select * from student_info where name = #{name}")
    StudentInfo findUserByName(String name);
}
